/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */

import { DistroFilterDimensionEnum } from '../enum/distro-filter-dimension-enum.js';
import { CoreModuleModelImpl } from '../model/module/core-module-model-impl.js';

import { DistroFilterConfig, DistroFilterHandler } from './distro-filter-handler.js';

/**
 * screenWindow对象校验
 * policy:include/exclude
 * value:["454*454"...]
 */
export class ScreenWindowHandler extends DistroFilterHandler {
  validateDistroFilterRequest(sourceDistroFilterConfig: DistroFilterConfig, targetDistroFilterConfig: DistroFilterConfig) {
    this.doRequest(sourceDistroFilterConfig, targetDistroFilterConfig, DistroFilterDimensionEnum.SCREEN_WINDOW);
  }

  getDimensionValue(distroFilterConfig: DistroFilterConfig): number[] | string[] | undefined {
    const screenWindowOpt = distroFilterConfig.distroFilterObj?.screenWindow;
    if (!screenWindowOpt) {
      return undefined;
    }

    const screenWindowPolicy = screenWindowOpt.policy;
    const screenWindowValue = screenWindowOpt.value;
    if (screenWindowPolicy === 'include') {
      return screenWindowValue;
    }
    if (screenWindowPolicy === 'exclude') {
      const moduleModel = this.projectModel.getModuleModelByName(distroFilterConfig.moduleName) as CoreModuleModelImpl;
      this.logger
        ._buildError('The exclude policy is not supported for screenWindow.')
        ._file(DistroFilterHandler.getDetailFilePath(this.projectModel, moduleModel))
        ._printErrorAndExit();
    }
    return undefined;
  }
}
